/*
 * Copyright (C) 2012 rothens
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package rpg.gfx.dialogs;

import java.util.ArrayList;
import rpg.RPG;
import rpg.gfx.Bitmap;
import rpg.ui.components.Component;
import rpg.ui.components.StaticTextures;
import rpg.util.BoundingBox;

/**
 *
 * @author rothens
 */
public abstract class Dialog extends Bitmap {
    ArrayList<Component> components = new ArrayList<Component>();
    int active = 0;
    int x;
    int y;
    Bitmap bg;
    BoundingBox bb;
    DialogHandler dh = new DialogHandler(this);
    
    public Dialog(int width, int height, Integer x, Integer y) {
        super(width, height);
        bg = new Bitmap(width, height);
        bg.clearWith(0xaa000001);
        StaticTextures.border_inactive.overlay(bg);
        this.y = (y == null) ? RPG.WINDOW_HEIGHT / 2 - height / 2 : y;
        this.x = (x == null) ? RPG.WINDOW_WIDTH / 2 - width / 2 : x;
        bb = new BoundingBox(this.x, this.y, width, height);
    }
    
    public void draw(){
        clear();
        draw(bg,0,0);
        for(Component c :  components){
            draw(c, c.getX(), c.getY());
        }
    }
    
    public int getX() {
        return x;
    }

    public void setX(Integer x) {
        this.x = (x == null) ? RPG.WINDOW_WIDTH / 2 - width / 2 : x;
        bb.setX(this.x);
    }

    public int getY() {
        return y;
    }

    public void setY(Integer y) {
        this.y = (y == null) ? RPG.WINDOW_HEIGHT / 2 - height / 2 : y;
        bb.setY(this.y);
    }
    
    
    public boolean isMouseOver(int x, int y){
        return bb.isMouseOver(x, y);
    }

    public ArrayList<Component> getComponents() {
        return components;
    }

    public void setComponents(ArrayList<Component> components) {
        this.components = components;
    }

    public int getActive() {
        return active;
    }

    public void setActive(int active) {
        this.active = active;
    }
    
    public void handleEvents(){
        dh.HandleEvents();
    }
    
    
    
    
        
}
